﻿using System;
using SKeeper.Domain.Invoices;
using SKeeper.Infrastructure;

namespace SKeeper.Application.ViewModels.Invoice
{
    public class ItemMovementViewModel
    {
        public int Id { get; set; }

        public int InvoiceId { get; set; }

        public int StoredItemId { get; set; }

        public int ItemId { get; set; }

        public double Quantity { get; set; }

        public double Price { get; set; }

        public double IndividualPrice { get { return this.Price / this.Quantity; } }

        public double PriceWithTax { get { return this.Price + this.Price * 0.18; } }

        public string Name { get; set; }

        public Units Unit { get; internal set; }

        internal StoredItemMovement ToStoredItemMovement()
        {
            return new StoredItemMovement
            {
                Id = this.Id,
                Quantity = this.Quantity,
                StoredItemId = this.StoredItemId,
                InvoiceId = this.InvoiceId,
            };
        }

        public static ItemMovementViewModel FromStoredItem(StoredItemMovement item)
        {
            return new ItemMovementViewModel
            {
                Id = item.Id,
                InvoiceId = item.InvoiceId,
                Price = item.Price,
                Quantity = item.Quantity,
                Name = item.StoredItem.Item.Name
            };
        }

    }
}
